package cn.panda.edu.service.impl;

import cn.panda.edu.dao.NoticeMapper;
import cn.panda.edu.model.Notice;
import cn.panda.edu.service.NoticeService;
import cn.panda.edu.util.Constant;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NoticeServiceImpl implements NoticeService {
	@Autowired
	private NoticeMapper noticeMapper;
	@Override
	public PageInfo<Notice> selectNoticeByPage(Integer pageindex, Integer pageSize) {
		Page<Notice> notices=PageHelper.startPage(pageindex, 5);
		noticeMapper.listNotice();
		PageInfo<Notice> pageInfo=new PageInfo<>(notices);
		return pageInfo;
	}

	@Override
	public Notice selectByPrimaryKey(Integer noticeId) {
		return noticeMapper.selectByPrimaryKey(noticeId);
	}
	/**
	 * 
	* Title: getAllNotice
	* Description: 苑庆涛
	* @param pageIndex
	* @param pageSize
	* @return 
	 */
	@Override
	public PageInfo<Notice> getAllNotice(Integer pageIndex, Integer pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageIndex,pageSize);
		List<Notice> list=noticeMapper.getAllNotice();
		PageInfo<Notice> pageInfo=new PageInfo<>(list);
		return pageInfo;
	}
	@Override
	public int insertSelective(Notice record) {
		// TODO Auto-generated method stub
		return noticeMapper.insert(record);
	}

	@Override
	public PageInfo<Notice> selectLikeByPrimaryKey(String noticeName, Date noticeDate, Integer pageIndex) {
		Map<String,Object> map=new HashMap<>();
		map.put("noticeName", noticeName);
		map.put("noticeDate", noticeDate);
		PageHelper.startPage(pageIndex, Constant.PAGE_SIZE);
		List<Notice> nList= noticeMapper.selectLikeByPrimaryKey(map);
		PageInfo<Notice> pageInfo=new PageInfo<>(nList);
		return pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(Integer noticeId) {
		// TODO Auto-generated method stub
		return noticeMapper.deleteByPrimaryKey(noticeId);
	}

	@Override
	public int updateByPrimaryKeySelective(Notice record) {
		// TODO Auto-generated method stub
		return noticeMapper.updateByPrimaryKeySelective(record);
	}
	
	
	
	
	
	
	
	
	
	
	
	
}
